package srjava.server;

import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;

import srjava.messages.*;

public class CoordinatorServerFullInfo {
	ServerInfo serverInfo;
	int numberOfTasks;
	LinkedList<Task> tasksToSend;
	LinkedList<TaskInfo> tasksToReturn;
	long last;
	
	public CoordinatorServerFullInfo() {
		this.numberOfTasks = 0;
	}
	
	public void incrementTasks() {
		numberOfTasks++;
	}
	
	public void decrementTasks() {
		numberOfTasks--;
	}
	
	public CoordinatorServerFullInfo(ServerInfo serverInfo, int numberOfTasks,
			LinkedList<TaskInfo> taskInfoList) {
		this.serverInfo = serverInfo;
		this.numberOfTasks = numberOfTasks;
		this.tasksToSend = new LinkedList<Task>();
		this.tasksToReturn = new LinkedList<TaskInfo>();
		this.last = (new Date()).getTime();
	}
	public LinkedList<Task> getTasksToSend() {
		return tasksToSend;
	}

	public void setTasksToSend(LinkedList<Task> taskToSend) {
		this.tasksToSend = taskToSend;
	}

	public ServerInfo getServerInfo() {
		return serverInfo;
	}
	
	public void setServerInfo(ServerInfo serverInfo) {
		this.serverInfo = serverInfo;
	}
	public int getNumberOfTasks() {
		return numberOfTasks;
	}
	public void setNumberOfTasks(int numberOfTasks) {
		this.numberOfTasks = numberOfTasks;
	}

	public LinkedList<TaskInfo> getTasksToReturn() {
		return tasksToReturn;
	}

	public void setTasksToReturn(LinkedList<TaskInfo> tasksToReturn) {
		this.tasksToReturn = tasksToReturn;
	}
	
	void tickAlive() {
		this.last = (new Date()).getTime();
	}
	
	boolean isAlive() {
		if ((new Date()).getTime() - last > 6000) {
			return false;
		}
		return true;
	}

	public ServerFullInfo getServerFullInfo() {
		ServerFullInfo pom = new ServerFullInfo();
		pom.setNumberOfTasks(numberOfTasks);
		pom.setAddress(serverInfo.getAddress());
		pom.setName(serverInfo.getName());
		pom.setServerStatus(serverInfo.getServerStatus());
		return pom;
	}

}
